﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace SMSPanasonic.Business
{
    public partial class pa_SmsStatistic
    {
    	#region public properties
		public int AgencyID { get; set; }
        //public DateTime Date_Time { get; set; }
		public int RegisterCount { get; set; }
		public int ExtentCount { get; set; }
		public int FailCount { get; set; }
		#endregion

		#region constructor
		public pa_SmsStatistic(){ }

		public pa_SmsStatistic(IDataReader rd)
		{
			this.AgencyID = (int)rd["AgencyID"];
            //this.Date_Time = (DateTime)rd["Date_Time"];
			this.RegisterCount = (int)rd["RegisterCount"];
			this.ExtentCount = (int)rd["ExtentCount"];
			this.FailCount = (int)rd["FailCount"];
		}
		#endregion

        public static pa_SmsStatistic GetOne(int AgencyID, int month, int year)
        {
            DateTime startDate = new DateTime(year, month, 1);
            DateTime endDate = startDate.AddMonths(1);
            using (SqlConnection conn = new SqlConnection(AppConfig.ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("usp_pa_SmsStatistic_Get", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandTimeout = 30;
                    cmd.Parameters.AddWithValue("@AgencyID", AgencyID);
                    cmd.Parameters.AddWithValue("@StartDate", startDate);
                    cmd.Parameters.AddWithValue("@EndDate", endDate);
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        while (rd.Read())
                        {
                            return new pa_SmsStatistic(rd);
                        }
                        return null;
                    }
                }
            }
        }

        public static void InsertOrUpdate(DataTable dtSource)
        {
            SqlParameter param = new SqlParameter("@SmsStatistic", dtSource);
            param.SqlDbType = SqlDbType.Structured;
            param.TypeName = "dbo.SmsStatisticType";
            SqlHelper.ExecuteNonQuery(AppConfig.ConnectionString, CommandType.StoredProcedure, "usp_pa_SmsStatistic_InsertOrUpdate", param);
        }
	}
}
